<script lang="ts" setup>
import { editPersonalChannel } from '../../../../api/personalChannel'
import { HttpStatusCode } from "axios"
import { ElMessage } from "element-plus"
import { usingNature, energyNature } from '../../../../enums/PersonalChannel'

const emits = defineEmits(['increase', 'closeShow'])
const prop = defineProps<{
  channelForm: ListPersonalChannel
}>()


const submitData = async () => {
  const res = await editPersonalChannel(prop.channelForm.id, prop.channelForm)
  if(res.statusCode === HttpStatusCode.Created || res.statusCode === HttpStatusCode.Ok) {
    console.log("成功")
    emits('increase', 1, '')
    emits('closeShow')
    ElMessage({
      message: '修改成功',
      type: 'success',
    })
  } else {
    ElMessage({
      message: '添加失败',
      type: 'error',
    })
  }
}
</script>

<template>
  <el-form
      label-position="top"
      label-width="100px"
      :model="prop.channelForm"
      style="max-width: 460px"
  >
    <el-form-item label="车源名称">
      <el-input v-model="prop.channelForm.personalCarName" />
    </el-form-item>
    <el-form-item label="品牌">
      <el-input v-model="prop.channelForm.brand" />
    </el-form-item>
    <el-form-item label="指导价(万)">
      <el-input-number v-model="prop.channelForm.personalCarPrice" :precision="1" :step="0.1">
      </el-input-number>
    </el-form-item>
    <el-form-item label="表显里程(万公里)">
      <el-input-number v-model="prop.channelForm.mileage" :precision="1" :step="0.1">
      </el-input-number>
    </el-form-item>
    <el-form-item label="上牌日期">
      <el-date-picker
          v-model="prop.channelForm.registrationDate"
          type="date"
          placeholder="选择日期"
          value-format="YYYY-MM-DD"
          size="default"
      />
    </el-form-item>
    <el-form-item label="车辆归属地">
      <el-input v-model="prop.channelForm.homeLocation" />
    </el-form-item>
    <el-form-item label="车辆所在地">
      <el-input v-model="prop.channelForm.location" />
    </el-form-item>
    <el-form-item label="能源种类">
      <el-select v-model="prop.channelForm.energy" placeholder="选择能源种类">
        <el-option
            v-for="item in energyNature"
            :key="item.value"
            :label="item.label"
            :value="item.value"
        />
      </el-select>
    </el-form-item>
    <el-form-item label="排放标准">
      <el-input v-model="prop.channelForm.emissionStandard" :disabled="prop.channelForm.energy === 2" />
    </el-form-item>
    <el-form-item label="保险到期日">
      <el-date-picker
          v-model="prop.channelForm.insuranceDate"
          type="date"
          placeholder="选择日期"
          value-format="YYYY-MM-DD"
          size="default"
      />
    </el-form-item>
    <el-form-item label="排量/变速箱">
      <el-input v-model="prop.channelForm.gearbox" :disabled="prop.channelForm.energy === 2" />
    </el-form-item>
    <el-form-item label="年检到期日">
      <el-date-picker
          v-model="prop.channelForm.annualInspection"
          type="date"
          placeholder="选择日期"
          value-format="YYYY-MM-DD"
          size="default"
      />
    </el-form-item>
    <el-form-item label="使用性质">
      <el-select v-model="prop.channelForm.usingNature" placeholder="选择使用性质">
        <el-option
            v-for="item in usingNature"
            :key="item.value"
            :label="item.label"
            :value="item.value"
        />
      </el-select>
    </el-form-item>
    <el-form-item label="联系电话">
      <el-input v-model="prop.channelForm.phone" />
    </el-form-item>
    <el-form-item label="车辆描述">
      <el-input :rows="2" type="textarea" v-model="prop.channelForm.description" />
    </el-form-item>
    <el-form-item label="所需积分">
      <el-input-number v-model="prop.channelForm.useCoin">
      </el-input-number>
    </el-form-item>
  </el-form>
  <el-button type="primary" @click="submitData">提交</el-button>
</template>

<style lang="less" scoped>

</style>